Change uses of \s within sed regexps -- some versions of sed do not support this
authoremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Mon, 28 Nov 2005 11:05:07 +0000 (11:05 +0000)
committeremellor@leeni.uk.xensource.com <emellor@leeni.uk.xensource.com>
Mon, 28 Nov 2005 11:05:07 +0000 (11:05 +0000)
escape.

Allow the vif-nat and vif-route scripts to have netdev specified, rather than
hard-coding eth0.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/examples/README.incompatibilities
tools/examples/vif-common.sh
tools/examples/vif-nat
tools/examples/vif-route

index 2d2c9503cf15169b30669fce36cd229965b0b3cf..87b2dbd62ef392217b773dd053d22356afc8d240 100644 (file)
@@ -23,3 +23,9 @@ appropriately.  See xen-network-common.sh for details.
 Gentoo doesn't have ifup/ifdown; appropriate alternatives are defined in
 xen-network-common.sh.
 
+
+sed
+---
+
+\s is not supported in regexps on Debian etch (sed 4.1.2), Ubuntu 4.10.  We
+hand-craft character classes instead.
index f7a488082a6a61e2915564ad32a3664c5a5db94f..18a0b6c88e47e69a9e5d9ed6a749945b35d7f221 100644 (file)
@@ -103,3 +103,37 @@ function handle_iptable()
       frob_iptable
   fi
 }
+
+
+##
+# ip_of interface
+#
+# Print the IP address currently in use at the given interface, or nothing if
+# the interface is not up.
+#
+function ip_of()
+{
+  ip addr show "$1" | sed -n 's/^.*inet \([0-9.]*\).*$/\1/p'
+}
+
+
+##
+# dom0_ip
+#
+# Print the IP address of the interface in dom0 through which we are routing.
+# This is the IP address on the interface specified as "netdev" as a parameter
+# to these scripts, or eth0 by default.  This function will call fatal if no
+# such interface could be found.
+#
+function dom0_ip()
+{
+  local nd=${netdev:-eth0}
+  local result=$(ip_of "$nd")
+  if [ -z "$result" ]
+  then
+      fatal
+"$netdev is not up.  Bring it up or specify another interface with " \
+"netdev=<if> as a parameter to $0."
+  fi
+  echo "$result"
+}
index 653038f2238cab8a5a7566e97449d48eaf006ce7..f94829689c7c8fac1de827e691b7c1c8ea7dd29e 100644 (file)
@@ -37,7 +37,7 @@ netmask=$netmask.$(( (($intmask & 0x00FF0000)) >> 16 ))
 netmask=$netmask.$(( (($intmask & 0x0000FF00)) >> 8 ))
 netmask=$netmask.$(( $intmask & 0x000000FF ))
 
-main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
+main_ip=$(dom0_ip)
 
 case "$command" in
     online)
index 84a6f2d0c634c99753a6c83072b7fbb5d74ad8f3..d733119d3058a0d4f6c97eb8b59832cde2133e27 100755 (executable)
@@ -23,7 +23,7 @@
 dir=$(dirname "$0")
 . "$dir/vif-common.sh"
 
-main_ip=$(ip addr show eth0 | sed -e '/inet /!d;s/^.*inet \([^\s*]\)\s.*$/\1/')
+main_ip=$(dom0_ip)
 
 case "$command" in
     online)